<template>
  <div id="app">
    <div class='app-content'>
      <router-view @childrenSongChanged='songChanged'></router-view>
    </div>
    <div class='z-player'>
      <zplayer :songList='songList' @childrenSongRemoved='delAllSong' @volumeChanged='childVolumeChanged' :volume='volume'></zplayer>
    </div>
  </div>
</template>
<script>
import VueZplayer from './components/ZPlayer'
export default {
  name: 'app',
  data () {
    return {
      volume: 2,
      songList: [] // 歌曲列表 播放列表 自己填了个默认值
    }
  },
  components: {
    'zplayer': VueZplayer
  },
  created () {
    let cache = JSON.parse(localStorage.getItem('cacheSongList'))
    if (!cache || cache.length === 0) {
    } else {
      this.songList = cache
    }
    console.log(this.songList)
    // 将音量存入cache
    if (!localStorage.getItem('volume')) {
      // console.log('音量是空的')
      this.volume = 8
    } else {
      // console.log('音量不是空的')
      this.volume = parseInt(localStorage.getItem('volume'))
    }
  },
  methods: {
    songChanged (obj) {
      this.songList.push(obj)
    },
    delAllSong () {
      this.songList = []
      localStorage.setItem('cacheSongList', this.songList)
      console.log('列表已清空..')
    },
    childVolumeChanged () {
      // 音量改变
      this.volume = parseInt(localStorage.getItem('volume'))
    }
  }
}
</script>

<style>
#app {
  font-family: 'Avenir', Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
  color: #2c3e50;
  position:absolute;
  top:0;
  left:0;
  right:0;
  bottom:0;
  z-index:9999;
}
.app-content{
  position:absolute;
  top:10px;
  left:10px;
  right:10px;
  bottom:140px;
  z-index:9999;
}
.z-player{
  position: absolute;
  left: 10px;
  right: 10px;
  bottom: 10px;
}
</style>
